package linkedList;

public class FindLastKNode {
}
class ListNode{
    int val;
    ListNode next;
    ListNode(int x){
        val = x;
    }
}
class Solution{
    public ListNode findKthFromEnd(ListNode head, int k){
        ListNode fast = head;
        ListNode slow = head;

        for(int i = 0; i < k;i++){
            if(fast == null){
                return null;
            }
            fast = fast.next;
        }
        while(fast != null){
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}